<template>
	<view class="container">
		<view :class="skinStyle" class="tui-edit-goods" v-if="shopcartCount > 0" style="position: fixed;z-index: 99;background-color: #F2F2F2;">
			<view>
				购物车共
				<text class="tui-goods-num theme-color">{{ shopcartCount }}</text>
				种商品
			</view>
			<view>
				<tui-button type="gray" :plain="true" shape="circle" width="160rpx" height="60rpx" :size="24" @click="editGoods">{{ isEdit ? '完成' : '编辑商品' }}</tui-button>
			</view>
		</view>
		<!-- <view v-show="saleShow()" ref="saleInfo" class="tui-sale-goods" style="position: fixed;z-index: 999;background-color: #F2F2F2;top: 84rpx;">
			<view v-for="(item, index) in saleArray" :key="index" style="display: block;">{{ item.word }}</view>
		</view> -->
		<view class="shopcartMescroll" v-if="!nodataFlg" :style="{ 'margin-top': mt + 'rpx' }">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" :up="upOption" @up="upCallback" :fixed="true">
				<view class="tui-cart-cell tui-mtop actView" :class="skinStyle" v-for="(actItem, actId) in activeList" :key="actId">
					<view class="tui-order-content" v-if="actItem.activeInfo.activeType != null">
						<view
							class="tui-goods-title tui-skeleton-fillet"
							style="background-color: #FFFFFF;padding-bottom: 10rpx;border-bottom: 1px solid #F2F2F2;"
							v-html="getSaleInfo(actItem.activeInfo)"
						></view>
					</view>
					<view class="tui-cart-cell fixedHeight" v-for="(item, index) in actItem.productInfo" :key="index" :class="{ 'tui-mtop': !actItem.name }">
						<tui-swipe-action :actions="actions" @click="handlerButton" :params="item" class="swipe-action">
							<template v-slot:content>
								<view class="tui-goods-item-wrap" :class="changeFlag?'swipe-change1':'swipe-change2'">
									<checkbox-group @change="selectSingle(item, actItem)" class="tui-checkbox">
										<checkbox :value="item.id" :checked="item.checked" color="#fff" style="padding:20rpx 0;"/>
									</checkbox-group>
									<view class="tui-goods-item" @tap="detail(item)">
										<image src="../../static/img/freeShipping.png" class="tui-goods-img imgMark" v-if="item.isSample !== 1 && item.isParcel === 1"></image>
										<image src="../../static/img/gift.png" class="tui-goods-img imgMark" v-if="item.isSample === 1"></image>
										<image :src="imgSrc + item.productThumbnailImageUrl" class="tui-goods-img" />
										<view class="tui-goods-info">
											<view class="tui-goods-title">{{ item.productName }}</view>
											<view class="tui-goods-model" v-if="item.productSpecificationName != null">
												<view class="tui-model-text">{{ item.productSpecificationName }}</view>
											</view>
											<view class="tui-price-box">
												<view class="tui-goods-price">￥{{ item.productDiscountPrice }}</view>
												<view class="tui-scale" @tap.stop="testFn($event)">
													<tui-numberbox
														:value="item.orderCount"
														:height="38"
														:width="70"
														:min="1"
														:max="item.virtualInventory"
														:index="index"
														@change="changeNum($event, actItem, actId)"
													></tui-numberbox>
												</view>
											</view>
										</view>
									</view>
								</view>
							</template>
						</tui-swipe-action>
					</view>
				</view>
				<!-- 商品失效 -->
				<view class="tui-cart-cell  tui-mtop" v-if="invalid.length > 0">
					<view class="tui-activity">
						<view class="tui-bold">失效商品</view>
						<view class="tui-buy">
							<tui-button @tap="deleteinvalid" type="gray" :plain="true" shape="circle" width="200rpx" height="56rpx" :size="24">清空失效商品</tui-button>
						</view>
					</view>
				</view>
				<view class="tui-cart-cell " v-if="invalid.length > 0">
					<view v-for="(item, index) in invalid" :key="index">
						<tui-swipe-action :actions="actions" @click="handlerButton" :params="item" class="swipe-action">
							<template v-slot:content>
								<view class="tui-goods-item-wrap">
									<view class="tui-checkbox tui-invalid-pr"><view class="tui-invalid-text">失效</view></view>
									<view class="tui-goods-item">
										<image :src="imgSrc + item.productThumbnailImageUrl" class="tui-goods-img opcity" />
										<view class="tui-goods-info">
											<view class="tui-goods-title tui-gray">{{ item.productName }}</view>
											<view class="tui-price-box tui-flex-center"><view class="tui-goods-invalid">产品失效</view></view>
											<!-- <view class="tui-price-box">
											<view class="tui-goods-invalid">{{item.goodsExpiredReason}}</view>
										</view> -->
											<view class="tui-price-box">
												<view class="tui-goods-price">￥{{ item.productDiscountPrice }}</view>
											</view>
										</view>
									</view>
								</view>
							</template>
						</tui-swipe-action>
					</view>
				</view>
				<!-- <view class="tui-safe-area" style="width: 100%;height: 400rpx;"></view> -->
			</mescroll-body>
			<view class="tui-tabbar tabbar-category" v-if="shopcartCount > 0">
				<view class="tui-checkAll" :class="skinStyle">
					<checkbox-group @tap="selectAll" class="check-group">
						<label class="tui-checkbox">
							<checkbox value="all" :checked="allChecked" color="#fff"></checkbox>
							<text class="tui-checkbox-pl">全选</text>
						</label>
					</checkbox-group>
					<view class="tui-total-price" v-if="!isEdit">
						合计:
						<text class="tui-bold price-color">￥{{ totalPrice }}</text>
					</view>
				</view>
				<view class="category-btn shopcartBtn">
					<!-- <view v-if="!isEdit" @click="btnPay">去结算(0)</view>
						<view v-else>删除</view> -->
					<tui-button width="200rpx" height="70rpx" :size="30" type="primary" shape="circle" v-if="!isEdit" @tap="btnPay">去结算({{ number }})</tui-button>
					<tui-button width="200rpx" height="70rpx" :size="30" type="black" shape="circle" :plain="true" v-else @tap="deleteCart">删除</tui-button>
				</view>
			</view>
		</view>
		<!-- <view class="nodata-wrap" v-if="nodataFlg" :style="{ height: height + 'px' }">
			<image class="img" src="../../static/img/img_nodata.png" mode=""></image>
			<text class="text">您还没有加购任何商品~</text> 
			
		</view> -->
		<mix-empty v-if="nodataFlg" :type="'default'" :backgroundColor="'#fff'"></mix-empty>
		<view :class="skinStyle"><foot-bar :current="selectedIndex" :skinStyle="skinStyle"></foot-bar></view>
		<!-- <loading v-if="isLoading"></loading> -->
		<tui-modal></tui-modal>
	</view>
</template>
<script>
import baseComponent from '@/components/baseComponent/baseComponent';
import footBar from '@/components/footbar/footbar';
import mixin from '@/utils/mixin.js';
import tuiSwipeAction from '@/components/swipe-action/swipe-action';
import tuiButton from '@/components/button/button';
import tuiNumberbox from '@/components/numberbox/numberbox';
import tuiDivider from '@/components/divider/divider';
import tuiLoadmore from '@/components/loadmore/loadmore';
import mixEmpty from '@/components/mix-empty/mix-empty.vue';
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
export default {
	mixins: [mixin, MescrollMixin],
	components: {
		baseComponent,
		footBar,
		tuiSwipeAction,
		tuiButton,
		tuiNumberbox,
		tuiDivider,
		tuiLoadmore,
		mixEmpty
	},

	data() {
		return {
			mt: 80,
			imgSrc: this.$store.state.imgUrl,
			selectedIndex: 2,
			activeList: [],
			pageId: '',
			nodataFlg: false,
			number: 0,
			isEdit: false,
			productCount: 0,
			upOption: {
				noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
				textNoMore: '-- 无更多信息 --'
			},
			allChecked: false,
			totalPrice: 0.0,
			invalid: [],
			isLoading: false,
			actions: [
				{
					name: '收藏',
					color: '#fff',
					fontsize: 30, //单位rpx
					width: 70, //单位px
					background: '#fd5521'
				},
				{
					name: '删除',
					color: '#fff',
					fontsize: 30, //单位rpx
					width: 70, //单位px
					background: '#FD3B31'
				}
			],

			indexNum: 1,
			saleArray: [],
			shopcartCount: 0,
			changeFlag:false,
			refreshFlg: false,
		};
	},
	computed: {},
	onLoad() {
	  // 监听页面刷新
	  //this.$eventHub.$off('shopcartRefresh');
	  this.$eventHub.$on('shopcartRefresh', () => {
	    this.refreshFlg = true;
	  });
	 },
	onShow() {
		if (this.refreshFlg) {
			this.refreshFlg = false;
			this.mescroll.resetUpScroll()
		}
		// this.mt = 80;
		// this.upCallback();
	},
	methods: {
		moneyFormat(num) {
			var result = parseFloat(num);
			result = Math.round(num * 100) / 100;
			var s_x = result.toString();
			var pos_decimal = s_x.indexOf('.');
			if (pos_decimal < 0) {
				pos_decimal = s_x.length;
				s_x += '.';
			}
			while (s_x.length <= pos_decimal + 2) {
				s_x += '0';
			}
			return s_x;
		},
		changeAmount(list) {
			console.log(this.mt);
			if (list.activeInfo.offInfo) {
				if (list.activeInfo.offInfo.promotionPrice !== 0) {
				// 满减活动
				let totalPrice = 0;
				let checkNum = 0;
				for (let a = 0; a < list.productInfo.length; a += 1) {
					if (list.productInfo[a].checked) {
						totalPrice += list.productInfo[a].orderCount * list.productInfo[a].productDiscountPrice;
						checkNum += 1;
					}
				}
				totalPrice = parseFloat(totalPrice.toFixed(2));
				if (totalPrice >= list.activeInfo.offInfo.promotionLimit) {
					if (list.activeInfo.offInfo.timesFlag === 0) {
						list.activeInfo.offInfo.offName = '已满' + list.activeInfo.offInfo.promotionLimit + '元,优惠' + list.activeInfo.offInfo.promotionPrice + '元';
					} else {
						const int = parseInt(totalPrice / list.activeInfo.offInfo.promotionLimit);
						const float = (int + 1) * list.activeInfo.offInfo.promotionLimit - totalPrice;

						const price1 = (int + 1) * list.activeInfo.offInfo.promotionLimit;
						const price2 = (int + 1) * list.activeInfo.offInfo.promotionPrice;
						list.activeInfo.offInfo.offName =
							'已享满' +
							this.moneyFormat(int * list.activeInfo.offInfo.promotionLimit) +
							'元减' +
							this.moneyFormat(int * list.activeInfo.offInfo.promotionPrice) +
							'元,再买' +
							this.moneyFormat(float) +
							'元，可享满' +
							this.moneyFormat(price1) +
							'元减' +
							this.moneyFormat(price2) +
							'元优惠';
					}
				} else if (totalPrice < list.activeInfo.offInfo.promotionLimit && checkNum > 0) {
					const price = list.activeInfo.offInfo.promotionLimit - totalPrice;
					list.activeInfo.offInfo.offName = '还差' + this.moneyFormat(price) + '元,可享优惠' + list.activeInfo.offInfo.promotionPrice + '元';
				} else {
					this.saleArray.forEach((item, index) => {
						if (item.id == list.activeInfo.offInfo.offId) {
							list.activeInfo.offInfo.offName = item.word;
						}
					});
				}
				}
			} else if (list.activeInfo.fgInfo) {
				// 满赠活动
				let totalPrice = 0;
				let checkNum = 0;
				for (let b = 0; b < list.productInfo.length; b += 1) {
					if (list.productInfo[b].checked) {
						totalPrice += list.productInfo[b].orderCount * list.productInfo[b].productDiscountPrice;
						checkNum += 1;
					}
				}
				totalPrice = parseFloat(totalPrice.toFixed(2));
				let giftName = '';
				list.activeInfo.fgInfo.activityFullGiveComplimentaryData.forEach((item, index) => {
					if (item.suitName) {
						giftName += item.giveNum + '件' + item.suitName;
					} else {
						giftName += item.giveNum + '件' + item.productName + '(' + item.specificationName + ')';
					}
				});

				if (totalPrice >= list.activeInfo.fgInfo.fgLimit) {
					if (list.activeInfo.fgInfo.isSuperpositionPrices === 0) {
						list.activeInfo.fgInfo.fgName = '已满' + list.activeInfo.fgInfo.fgLimit + '元,赠送' + giftName;
					} else {
						const int = parseInt(totalPrice / list.activeInfo.fgInfo.fgLimit);
						const float = (int + 1) * list.activeInfo.fgInfo.fgLimit - totalPrice;
						list.activeInfo.fgInfo.fgName = '已享满赠活动,再买' + this.moneyFormat(float) + '元，可再赠送' + giftName;
					}
				} else if (totalPrice < list.activeInfo.fgInfo.fgLimit && checkNum > 0) {
					const price = list.activeInfo.fgInfo.fgLimit - totalPrice;
					list.activeInfo.fgInfo.fgName = '还差' + this.moneyFormat(price) + '元,将赠送' + giftName;
				} else {
					this.saleArray.forEach((item, index) => {
						if (item.id == list.activeInfo.fgInfo.fgId) {
							list.activeInfo.fgInfo.fgName = item.word;
						}
					});
				}
			} else if (list.activeInfo.activityBuyGiveInfo) {
				// 买赠活动
				let totalCount = 0;
				let checkNum = 0;
				let totalPrice = 0;
				for (let c = 0; c < list.productInfo.length; c += 1) {
					if (list.productInfo[c].checked) {
						totalCount += list.productInfo[c].orderCount;
						totalPrice += list.productInfo[c].orderCount * list.productInfo[c].productDiscountPrice;
						checkNum += 1;
					}
				}
				totalCount = parseInt(totalCount);
				let giftName = '';
				list.activeInfo.activityBuyGiveInfo.activityBuyGiveComplimentaryData.forEach((item, index) => {
					if (!item.productName) {
						if (item.suitName) {
							giftName += item.giveNum + '件' + item.suitName;
						} else {
							giftName += item.giveNum + '件' + list.activeInfo.activityBuyGiveInfo.activityProductData[0].suitName;
						}
					} else {
						giftName += item.giveNum + '件' + item.productName + '(' + item.specificationName + ')';
					}
				});
				if (totalCount >= list.activeInfo.activityBuyGiveInfo.activityProductData[0].giveNum) {
					if (list.activeInfo.activityBuyGiveInfo.giveMultiple === 0) {
						list.activeInfo.activityBuyGiveInfo.activityName = '已享买' + list.activeInfo.activityBuyGiveInfo.activityProductData[0].giveNum + '件赠送' + giftName;
					} else {
						const int = parseInt(totalCount / list.activeInfo.activityBuyGiveInfo.activityProductData[0].giveNum);
						const float = (int + 1) * list.activeInfo.activityBuyGiveInfo.activityProductData[0].giveNum - totalCount;
						list.activeInfo.activityBuyGiveInfo.activityName = '已享受买赠活动,再购买' + float + '件可继续赠送' + giftName;
					}
				} else if (totalCount < list.activeInfo.activityBuyGiveInfo.activityProductData[0].giveNum && checkNum > 0) {
					const price = list.activeInfo.activityBuyGiveInfo.activityProductData[0].giveNum - totalCount;
					list.activeInfo.activityBuyGiveInfo.activityName = '还差' + price + '件赠送' + giftName;
				} else {
					this.saleArray.forEach((item, index) => {
						if (item.id == list.activeInfo.activityBuyGiveInfo.activityProductData[0].specificationId) {
							list.activeInfo.activityBuyGiveInfo.activityName = item.word;
						}
					});
				}
			} else if (list.activeInfo.promotionDiscountInfo) {
				// 满几件半价
				let totalCount = 0;
				let checkNum = 0;
				let totalPrice = 0;
				for (let d = 0; d < list.productInfo.length; d += 1) {
					if (list.productInfo[d].checked) {
						totalCount += list.productInfo[d].orderCount;
						totalPrice += list.productInfo[d].orderCount * list.productInfo[d].productDiscountPrice;
						checkNum += 1;
					}
				}
				totalCount = parseInt(totalCount);
				if (totalCount >= list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount) {
					if (list.activeInfo.promotionDiscountInfo.multipleFlag === 1) {
						list.activeInfo.promotionDiscountInfo.promotionDiscountName =
							'已享满' +
							list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount +
							'件第' +
							list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount +
							'件优惠为' +
							+list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionPrice +
							'元';
					} else {
						const int = parseInt(totalCount / list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount);
						const float = (int + 1) * list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount - totalCount;

						list.activeInfo.promotionDiscountInfo.promotionDiscountName =
							'已享受每满' +
							list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount +
							'件第' +
							list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount +
							'件' +
							+list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionPrice +
							'元,继续购买' +
							float +
							'件商品可再次享受此优惠';
					}
				} else if (totalCount < list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount && checkNum > 0) {
					const price = list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount - totalCount;
					list.activeInfo.promotionDiscountInfo.promotionDiscountName =
						'还差' +
						price +
						'件商品即可享受第' +
						list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionCount +
						'件优惠为' +
						+list.activeInfo.promotionDiscountInfo.activityProductData[0].promotionPrice +
						'元';
				} else {
					this.saleArray.forEach((item, index) => {
						if (item.id == list.activeInfo.promotionDiscountInfo.activityProductData[0].specificationId) {
							list.activeInfo.promotionDiscountInfo.promotionDiscountName = item.word;
						}
					});
				}
			} else if (list.activeInfo.activityBuyDiscount) {
				// 满折活动信息
				let totalCount = 0;
				let checkNum = 0;
				let totalPrice = 0;
				for (let e = 0; e < list.productInfo.length; e += 1) {
					if (list.productInfo[e].checked) {
						totalCount += list.productInfo[e].orderCount;
						totalPrice += list.productInfo[e].orderCount * list.productInfo[e].productDiscountPrice;
						checkNum += 1;
					}
				}
				totalCount = parseInt(totalCount);
				if (totalCount >= list.activeInfo.activityBuyDiscount.buyCount) {
					list.activeInfo.activityBuyDiscount.activityName = '已享活动商品' + this.moneyFormat(list.activeInfo.activityBuyDiscount.discount * 10) + '折优惠';
				} else if (totalCount < list.activeInfo.activityBuyDiscount.buyCount && checkNum > 0) {
					const count = list.activeInfo.activityBuyDiscount.buyCount - totalCount;
					list.activeInfo.activityBuyDiscount.activityName = '还差' + count + '件,可享' + this.moneyFormat(list.activeInfo.activityBuyDiscount.discount * 10) + '折优惠';
				} else {
					this.saleArray.forEach((item, index) => {
						if (item.id == list.activeInfo.activityBuyDiscount.activityId) {
							list.activeInfo.activityBuyDiscount.activityName = item.word;
						}
					});
				}
			}
		},

		getSaleWord() {
			this.saleArray = [];
			for (let i = 0; i < this.activeList.length; i += 1) {
				const item = this.activeList[i].activeInfo;
				let id = '';
				let word = '';
				if (item.offInfo) {
					// 满减活动
					id = item.offInfo.offId;
					word = item.offInfo.offName;
				} else if (item.fgInfo) {
					// 满赠活动
					id = item.fgInfo.fgId;
					word = item.fgInfo.fgName;
				} else if (item.activityBuyGiveInfo) {
					// 买赠活动
					id = item.activityBuyGiveInfo.activityProductData[0].specificationId;
					word = item.activityBuyGiveInfo.activityName;
				} else if (item.promotionDiscountInfo) {
					// 满几件半价
					id = item.promotionDiscountInfo.activityProductData[0].specificationId;
					word = item.promotionDiscountInfo.promotionDiscountName;
				} else if (item.activityBuyDiscount) {
					// 满折活动信息
					id = item.activityBuyDiscount.activityId;
					word = item.activityBuyDiscount.activityName;
				}
				this.saleArray.push({
					id: id,
					word: word
				});
			}
		},

		testFn(e) {
			e.preventDefault();
		},
		handlerButton(e) {
			this.isLoading = true;
			const id = [];
			id.push({
				id: e.item.id
			});
			if (e.index === 1) {
				this.deleteCartGoods(id, 1);
			} else {
				const params = {};
				if (!e.item.productId) {
					uni.showToast({
						icon: 'none',
						title: '套装不能加入收藏夹'
					});
					return;
				}
				params.productId = e.item.productId;
				this.$http.collectionProductCreate(params).then(res => {
					if (res.status == 0) {
						uni.showToast({
							icon: 'none',
							title: '移入收藏夹成功'
						});
						this.deleteCartGoods(id, 2);
					} else {
						this.isLoading = false;
					}
				});
			}
		},
		editShopcart() {
			let updateInfo = [];
			this.activeList.forEach((item2, index2) => {
				item2.productInfo.forEach((item, index) => {
					let suitId = '';
					if (item.suitId != null) {
						suitId = item.suitId;
					}
					updateInfo.push({
						suitId: suitId,
						productSpecificationId: item.productSpecificationId,
						orderCount: item.orderCount
					});
				});
			});
			let params = {
				updateInfo: updateInfo,
				buyItemFlg: 1
			};
			this.$http.editShopcart(params).then(res => {
				if (!res.status == 0) {
					uni.showToast({
						icon: 'none',
						title: '购物车修改失败'
					});
				}
			});
		},
		editShopcartNum(item) {
			let updateInfo = [];
			let suitId = '';
			if (item.suitId != null) {
				suitId = item.suitId;
			}
			updateInfo.push({
				suitId: suitId,
				productSpecificationId: item.productSpecificationId,
				orderCount: item.orderCount
			});
			let params = {
				updateInfo: updateInfo,
				buyItemFlg: 1
			};
			this.$http.editShopcart(params).then(res => {
				if (!res.status == 0) {
					uni.showToast({
						icon: 'none',
						title: '购物车修改失败'
					});
				}
			});
		},
		// 结算
		btnPay() {
			var goodsList = [];
			this.activeList.forEach((item2, index2) => {
				item2.productInfo.forEach((item, index) => {
					if (item.checked) {
						const active = item2.activeInfo;
						let offId = null;
						if (active.offInfo) {
							offId = active.offInfo.offId;
						}
						let fgId = null;
						if (active.fgInfo) {
							fgId = active.fgInfo.fgId;
						}
						let activityGiveId = null;
						if (active.activityBuyGiveInfo) {
							activityGiveId = active.activityBuyGiveInfo.activityId;
						}
						let promotionDiscountId = null;
						if (active.promotionDiscountInfo) {
							promotionDiscountId = active.promotionDiscountInfo.promotionDiscountId;
						}
						let activityId = null;
						if (active.activityBuyDiscount) {
							activityId = active.activityBuyDiscount.activityId;
						}
						let suitId = null;
						if (item.suitId) {
							suitId = item.suitId;
						}
						goodsList.push({
							specificationId: item.productSpecificationId,
							productsCount: item.orderCount,
							offId: offId,
							fgId: fgId,
							activityGiveId: activityGiveId,
							promotionDiscountId: promotionDiscountId,
							activityId: activityId,
							suitId: suitId,
							id: item.id,
						});
						console.log(goodsList);
					}
				});
			});

			if (goodsList.length == 0) {
				uni.showToast({
					title: '您还没有选择商品',
					icon: 'none'
				});
				return;
			}
			console.log(goodsList);
			uni.setStorageSync('carGoodsList', goodsList);
			uni.navigateTo({
				url: '../../packageA/pages/submitOrder/submitOrder?shopcartFlag=1'
			});
			// this.mescroll.resetUpScroll();
		},
		detail(item) {
			if (item.productId) {
				this.$util.gotoGoodsDetail('productId', item.productId);
				// this.mescroll.resetUpScroll();
			} else if (item.suitId) {
				this.$util.gotoGoodsDetail('suitId', item.suitId);
				// this.mescroll.resetUpScroll();
			}
		},
		deleteinvalid() {
			var carId = [];
			this.invalid.forEach((item, index) => {
				carId.push({
					id: item.id
				});
			});
			this.deleteCartGoods(carId, 1);
		},
		//删除购物车商品
		deleteCart() {
			var carId = [];
			var num = 0;
			this.activeList.forEach((item2, index2) => {
				item2.productInfo.forEach((item, index) => {
					if (item.checked) {
						carId.push({
							id: item.id
						});
						num += 1;
					}
				});
			});
			if (num == 0) {
				uni.showToast({
					title: '您还没有选择商品',
					icon: 'none'
				});
				return;
			}
			this.deleteCartGoods(carId, 1);
		},
		//删除购物车商品
		deleteCartGoods(id, flag) {
			let params = {
				ids: id
			};
			this.isLoading = true;
			this.$http.editShopcart(params).then(res => {
				if (res.status == 0) {
					if (flag === 1) {
						uni.showToast({
							icon: 'none',
							title: '删除成功'
						});
					}
					this.activeList = [];
					this.mescroll.resetUpScroll();
				} else {
					this.isLoading = false;
				}
			});
		},
		//改变当前编辑状态
		editGoods() {
			this.isEdit = !this.isEdit;
		},
		//计算选中商品的总价
		getTotalPrice() {
			let totalPrice = 0;
			this.activeList.forEach((item2, index) => {
				item2.productInfo.map(item => {
					item.checked ? (totalPrice += item.orderCount * item.productDiscountPrice) : (totalPrice += 0);
				});
			});
			this.totalPrice = totalPrice.toFixed(2);
		},
		//改变购买数量
		changeNum(e, item, id) {
			console.log(e);
			this.activeList[id].productInfo[e.index].orderCount = e.value;
			var num = 0;
			this.activeList.forEach((item2, index2) => {
				item2.productInfo.forEach((item, index) => {
					if (item.checked) {
						num++;
					}
				});
			});
			this.number = num;
			this.getTotalPrice();
			this.changeAmount(item);
			this.editShopcartNum(this.activeList[id].productInfo[e.index]);
		},

		// 单个商品的选择
		selectSingle(item, actItem) {
			this.changeFlag=!this.changeFlag;
			item.checked = !item.checked;
			this.changeAmount(actItem);
			if (!item.checked) {
				this.allChecked = false;
			} else {
				// 判断每一个商品是否是被选择的状态
				var num = 0;
				var count = 0;
				this.activeList.forEach((item2, index2) => {
					item2.productInfo.forEach((item, index) => {
						count += 1;
						if (item.checked) {
							num++;
						}
					});
				});
				if (count === num && count > 0) {
					this.allChecked = true;
				} else {
					this.allChecked = false;
				}
			}
			var num = 0;
			this.activeList.forEach((item2, index) => {
				item2.productInfo.forEach((item, index) => {
					if (item.checked) {
						num++;
					}
				});
			});
			this.number = num;
			this.getTotalPrice();
		},
		//全选、全不选
		selectAll() {
			this.allChecked = !this.allChecked;
			if (this.allChecked) {
				this.activeList.forEach((item2, index) => {
					item2.productInfo.map(item => {
						item.checked = true;
						this.changeAmount(item2);
					});
				});
			} else {
				this.activeList.forEach((item2, index) => {
					item2.productInfo.map(item => {
						item.checked = false;
						this.changeAmount(item2);
					});
				});
			}
			var num = 0;
			this.activeList.forEach((item2, index) => {
				item2.productInfo.forEach((item, index) => {
					if (item.checked) {
						num++;
					}
				});
			});
			this.number = num;
			this.getTotalPrice();
		},
		getSaleInfo(item) {
			if (item.offInfo) {
				// 满减活动
				return item.offInfo.offName;
			} else if (item.fgInfo) {
				// 满赠活动
				return item.fgInfo.fgName;
			} else if (item.activityBuyGiveInfo) {
				// 买赠活动
				return item.activityBuyGiveInfo.activityName;
			} else if (item.promotionDiscountInfo) {
				// 满几件半价
				return item.promotionDiscountInfo.promotionDiscountName;
			} else if (item.activityBuyDiscount) {
				// 满折活动信息
				return item.activityBuyDiscount.activityName;
			}
		},
		upCallback() {
			this.$http
				.getShopcart()
				.then(res => {
					if (res.status == 0) {
						this.allChecked = false;
						this.number = 0;
						this.totalPrice = 0.0;
						let shopcartCount = 0;
						var data = res.data;
						if (data == null) {
							data = [];
						}
						this.mescroll.endSuccess(data.length);
						var productList = [];
						var invalid = [];
						for (var i = 0; i < data.length; i++) {
							productList.push({
								activeInfo: data[i].activeInfo,
								productInfo: []
							});

							for (var j = 0; j < data[i].productInfo.length; j++) {
								if (data[i].productInfo[j].isInvalid == 1) {
									invalid.push(data[i].productInfo[j]);
								} else if (data[i].productInfo[j].isInvalid == 0) {
									this.allChecked = false;

									data[i].productInfo[j].checked = false;

									productList[i].productInfo.push(data[i].productInfo[j]);
									shopcartCount += 1;
								}
							}
						}
						if (shopcartCount === 0) {
							this.mt = 0;
						}

						this.shopcartCount = shopcartCount;
						this.activeList = productList;
						this.invalid = invalid;
						this.getSaleWord();
					}
					this.isLoading = false;
				})
				.catch(() => {
					this.mescroll.endErr();
				});
		}
	}
};
</script>

<style lang="scss">
.fixedHeight{
	height: 288rpx !important;
}
.container{
	padding-bottom: calc(constant(safe-area-inset-bottom) + 194rpx);
	padding-bottom: calc(env(safe-area-inset-bottom) + 194rpx);
	.mescroll-empty{
		padding-top: 26vh;
	}
}
.shopcartMescroll .mescroll-totop {
	bottom: 198rpx !important;
}
.actView {
	width: 97% !important;
	margin: 10px auto;
	border-radius: 10px;
}
.tui-order-content {
	width: 100%;
	padding: 24rpx 30rpx;
	box-sizing: border-box;
	background: #fff;
	font-size: 24rpx;
	line-height: 30rpx;
}
.tui-goods-title {
}

.imgMark {
	position: absolute;
	width: 100rpx !important;
	height: 100rpx !important;
	top: 10rpx;
	left: 82rpx;
	z-index: 99999;
}
.shopcartBtn {
	padding-bottom: 15rpx;
}

/deep/ .uni-scroll-view::-webkit-scrollbar {
	/* 隐藏滚动条，但依旧具备可以滚动的功能 */
	display: none;
}
.nodata-wrap {
	width: 100%;
	height: 100%;
	background: #fff;
	.img {
		width: 300rpx;
		height: 300rpx;
		margin: 15% auto 50rpx auto;
		display: block;
		img {
			width: 100%;
			opacity: 0.5;
		}
	}
	.text {
		display: block;
		text-align: center;
		color: #ccc;
	}
}
// /deep/ uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before{
// 	color:#fff;
// }
// /deep/ uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before{
// 	font-size: 32rpx;
// 	color:$themeColor;
// }
// /deep/ uni-checkbox.gray-checkbox .uni-checkbox-input{
// 	background:$borderColor;
// }
.tui-mtop {
	margin-top: 20rpx;
}

.tui-edit-goods {
	width: 100%;
	border-radius: 12rpx;
	overflow: hidden;
	padding: 24rpx 30rpx 12rpx 30rpx;
	box-sizing: border-box;
	display: flex;
	justify-content: space-between;
	align-items: center;
	color: #333;
	font-size: 24rpx;
}

.tui-sale-goods {
	width: 100%;
	border-radius: 12rpx;
	padding: 24rpx 30rpx 12rpx 30rpx;
	color: #333;
	font-size: 24rpx;
}

.tui-goods-num {
	font-weight: bold;
	//color: $themeColor;
}

.tui-cart-cell {
	width: 100%;
	background: #ffffff;
	overflow: hidden;
	padding-bottom: 10rpx;
}
.swipe-action {
	.swipe-change1{
		padding-top:1rpx;
	}
	.swipe-change2{
		padding-top:0rpx;
	}
	.tui-swipeout-item {
		padding: 30rpx 0;
	}
}
.tui-goods-item-wrap {
	padding: 0 30rpx;
	display: flex;

	.tui-checkbox {
		width: 55rpx;
		display: flex;
		align-items: center;
		float: left;
		margin-right: 10rpx;
	}
	.tui-goods-item {
		flex: 1;
		// width:calc(100%-110rpx);
		display: flex;
		box-sizing: border-box;
	}
}

.tui-goods-img {
	width: 220rpx;
	height: 220rpx;
	border-radius: 12rpx;
	flex-shrink: 0;
	display: block;
}

.tui-goods-info {
	flex: 1;
	width: 100%;
	padding-left: 20rpx;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	justify-content: space-between;
	box-sizing: border-box;
	overflow: hidden;
}

.tui-goods-title {
	width: 100%;
	line-height: 28rpx;

	white-space: normal;
	word-break: break-all;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	// -webkit-line-clamp: 2;
	font-size: 26rpx;
	color: #333;
}

.tui-goods-model {
	max-width: 100%;
	color: #333;
	background: #f5f5f5;
	border-radius: 40rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 16rpx;
	box-sizing: border-box;
}

.tui-model-text {
	max-width: 100%;
	transform: scale(0.9);
	transform-origin: 0 center;
	font-size: 26rpx;
	line-height: 32rpx;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.tui-price-box {
	width: 100%;
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
}

.tui-goods-price {
	font-size: 34rpx;
	font-weight: 500;
	color: $red;
}

.tui-scale {
	transform-origin: 100% 100%;
}

.tui-activity {
	font-size: 28rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 30rpx 20rpx 30rpx;
	box-sizing: border-box;
	height: 110rpx;
}

.tui-buy {
	display: flex;
	align-items: center;
}

.tui-bold {
	font-weight: bold;
}

/*猜你喜欢*/
.tui-youlike {
	padding-left: 12rpx;
}

.tui-product-list {
	display: flex;
	justify-content: space-between;
	flex-direction: row;
	flex-wrap: wrap;
	box-sizing: border-box;
}

.tui-product-container {
	flex: 1;
	margin-right: 2%;
}

.tui-product-container:last-child {
	margin-right: 0;
}

.tui-pro-item {
	width: 100%;
	margin-bottom: 4%;
	background: #fff;
	box-sizing: border-box;
	border-radius: 12rpx;
	overflow: hidden;
}

.tui-pro-img {
	width: 100%;
	display: block;
}

.tui-pro-content {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	box-sizing: border-box;
	padding: 20rpx;
}

.tui-pro-tit {
	color: #2e2e2e;
	font-size: 26rpx;
	word-break: break-all;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

.tui-pro-price {
	padding-top: 18rpx;
}

.tui-factory-price {
	font-size: 24rpx;
	color: #a0a0a0;
	text-decoration: line-through;
	padding-left: 12rpx;
}

.tui-pro-pay {
	padding-top: 10rpx;
	font-size: 24rpx;
	color: #656565;
}

.tabbar-category {
	bottom: 97rpx !important;
	padding-bottom: env(safe-area-inset-bottom) !important;
}
// .tui-safe-area {
// 	// height: 400rpx;
// 	width: 100%;
// }

.tui-invalid-pr {
	// width: 75rpx !important;
}
.tui-invalid-text {
	width: 60rpx;
	// margin-right: 4rpx;
	text-align: center;
	font-size: 24rpx;
	color: #fff;
	background: rgba(0, 0, 0, 0.3);
	transform: scale(0.8);
	transform-origin: center center;
	border-radius: 4rpx;
	flex-shrink: 0;
}
.tui-gray {
	color: #b2b2b2 !important;
}
.tui-flex-center {
	// align-items: center !important;
	margin-bottom: 70rpx;
}
.tui-goods-invalid {
	color: #555;
	font-size: 24rpx;
}
</style>
